home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 1999-08-27 | 5.3 KB | 195 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- END
- Attribute VB_Name = "cRemover"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- Option Explicit
-
- Public Event NoMoreProjects()
-
- '-------------Private Propertys-----------------'
- Private m_NumProjs As Integer
- Private m_Selected As Integer
- Private Const sKeyName As String = "SOFTWARE\Microsoft\Visual Basic\5.0\RecentFiles"
- Private Const MAX_PROJS As Integer = 50
-
- '-------------Public Propertys------------------'
- Public Property Get NumProjs(lstBox As ListBox) As Integer
- NumProjs = lstBox.ListCount
- End Property
-
- Public Property Let NumProjs(lstBox As ListBox, ByVal iNewValue As Integer)
- m_NumProjs = iNewValue
- End Property
-
- '=============================================='
-
- Public Property Get Selected() As Integer
- Selected = m_Selected
- End Property
-
- Public Property Let Selected(ByVal sNewValue As Integer)
- m_Selected = sNewValue
- End Property
-
-
- '------------Methods----------------------------'
- ' remove selected projects
- Sub Remove(sValueName As String)
- Dim m_sValueName As String
- Dim i As Integer
- Dim Result As Integer
-
- m_NumProjs = GetNumProjs()
- For i = 1 To MAX_PROJS
- m_sValueName = QueryValue(HKEY_CURRENT_USER, sKeyName, CStr(i))
-
- If m_sValueName <> "" Then
- Result = StrComp(m_sValueName, sValueName, vbTextCompare)
-
- If Result = 0 Then
- ' go into the reg and remove the desired value
- DeleteValue HKEY_CURRENT_USER, sKeyName, CStr(i)
- ' adjust the number of projects
- m_NumProjs = m_NumProjs - 1
-
- If m_NumProjs < 1 Then
- RaiseEvent NoMoreProjects
- End If
- Exit Sub
- End If
-
- End If
- Next i
-
- MsgBox "Key Not Found!", vbCritical, "No Key"
-
- End Sub
-
-
- ' get all known projects and apply them
- ' to the passed in listbox
- Sub GetProjs(lstBox As ListBox)
- Dim cnt As Integer
- Dim CurProj As String
- Dim ProjNameOnly As String
- Dim ProjPath As String
- Dim FrmtName As String
- Dim NumProjs As Integer
-
- NumProjs = GetNumProjs()
- If NumProjs < 1 Then RaiseEvent NoMoreProjects
- '--- Get all the values under _
- HKEY_CURRENT_USER\SOFTWARE\Microsoft\Visual Basic\5.0\RecentFiles
-
- For cnt = 1 To MAX_PROJS
- CurProj = QueryValue(HKEY_CURRENT_USER, sKeyName, CStr(cnt))
- If CurProj <> "" Then ' only add to list if value is something
- ProjPath = GetFileNameFromPath(CurProj)
- ProjNameOnly = GetFileNameNoExt(ProjPath)
- lstBox.AddItem " -- " & ProjNameOnly
- End If
- Next
- End Sub
-
-
- Private Function GetNumProjs() As Integer
- Dim TotalProjs As Integer
- Dim MaybeProj As String
- Dim i As Integer
-
- For i = 1 To MAX_PROJS
- MaybeProj = QueryValue(HKEY_CURRENT_USER, sKeyName, CStr(i))
-
- If MaybeProj <> "" Then ' if it = something add one
- TotalProjs = TotalProjs + 1
- End If
- Next
-
- GetNumProjs = TotalProjs
- End Function
-
- ' remove all projects from the registry
- ' and passed in listbox
- Sub ClearAll(lstBox As ListBox)
- Dim CurProj As String
-
- ' if a value = anything Delete it
- Dim cnt As Integer
-
- For cnt = 1 To MAX_PROJS
- CurProj = QueryValue(HKEY_CURRENT_USER, sKeyName, CStr(cnt))
- If CurProj <> "" Then
- ' go into the reg and remove the desired value
- DeleteValue HKEY_CURRENT_USER, sKeyName, CStr(cnt)
- End If
- Next
- RaiseEvent NoMoreProjects
- End Sub
-
-
- ' return the selcted projects path
- Sub GetSelected(intProjIndex As Integer, SelName As String, label As label)
- '
- Dim ProjPath As String, i As Integer
- Dim ProjName As String
- Dim Result As Integer
-
- intProjIndex = intProjIndex + 1
-
- ' trim down selname
- SelName = Right(SelName, Len(SelName) - 4)
-
- ProjPath = QueryValue(HKEY_CURRENT_USER, sKeyName, CStr(intProjIndex))
-
- If ProjPath <> "" Then ' found one..... but is it the one
- 'get it's name
- ProjName = GetFileNameNoExt(ProjPath)
- ProjName = GetFileNameFromPath(ProjName)
- ' is it the one
- Result = StrComp(ProjName, SelName, vbTextCompare)
-
- If Result = 0 Then
- label = ProjPath
- 'found it so exit....done
- Exit Sub
- End If
-
- End If
-
- For i = (intProjIndex) To MAX_PROJS
-
- ProjPath = QueryValue(HKEY_CURRENT_USER, sKeyName, CStr(intProjIndex))
-
- If ProjPath <> "" Then ' found one..... but is it the one
- 'get it's name
- ProjName = GetFileNameNoExt(ProjPath)
- ProjName = GetFileNameFromPath(ProjName)
- ' is it the one
- Result = StrComp(ProjName, SelName, vbTextCompare)
- If Result = 0 Then
- label = ProjPath
- 'found it so exit....done
- Exit For
- End If
-
- End If
- ' else....increment for another go
- intProjIndex = intProjIndex + 1
- Next
-
-
- If ProjPath <> "" Then
- m_Selected = intProjIndex + 1
- End If
- End Sub
-
-
-
-
-
-